package com.ruoyi.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.FormSettingSmall;
import com.ruoyi.manage.service.IFormSettingSmallService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单小项Controller
 * 
 * @author zww
 * @date 2025-07-15
 */
@RestController
@RequestMapping("/manage/formsettingsmall")
public class FormSettingSmallController extends BaseController
{
    @Autowired
    private IFormSettingSmallService formSettingSmallService;

    /**
     * 查询单小项列表
     */
    @PreAuthorize("@ss.hasPermi('manage:formsettingsmall:list')")
    @GetMapping("/list")
    public TableDataInfo list(FormSettingSmall formSettingSmall)
    {
        startPage();
        List<FormSettingSmall> list = formSettingSmallService.selectFormSettingSmallList(formSettingSmall);
        return getDataTable(list);
    }

    /**
     * 导出单小项列表
     */
    @PreAuthorize("@ss.hasPermi('manage:formsettingsmall:export')")
    @Log(title = "单小项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FormSettingSmall formSettingSmall)
    {
        List<FormSettingSmall> list = formSettingSmallService.selectFormSettingSmallList(formSettingSmall);
        ExcelUtil<FormSettingSmall> util = new ExcelUtil<FormSettingSmall>(FormSettingSmall.class);
        util.exportExcel(response, list, "单小项数据");
    }

    /**
     * 获取多小项详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:formsettingsmall:query')")
    @GetMapping(value = "/{formSettingBigId}")
    public AjaxResult getInfo(@PathVariable("formSettingBigId") Long formSettingBigId)
    {
        return success(formSettingSmallService.selectFormSettingSmallByFormSettingBigId(formSettingBigId));
    }

    /**
     * 新增单小项
     */
    @PreAuthorize("@ss.hasPermi('manage:formsettingsmall:add')")
    @Log(title = "单小项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<FormSettingSmall> formSettingSmallList)
    {
        return toAjax(formSettingSmallService.insertFormSettingSmall(formSettingSmallList));
    }

    /**
     * 修改单小项
     */
    @PreAuthorize("@ss.hasPermi('manage:formsettingsmall:edit')")
    @Log(title = "单小项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FormSettingSmall formSettingSmall)
    {
        formSettingSmall.setUpdateBy(getUsername());
        return toAjax(formSettingSmallService.updateFormSettingSmall(formSettingSmall));
    }

    /**
     * 删除单小项
     */
    @PreAuthorize("@ss.hasPermi('manage:formsettingsmall:remove')")
    @Log(title = "单小项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{formSettingSmallIds}")
    public AjaxResult remove(@PathVariable Long[] formSettingSmallIds)
    {
        return toAjax(formSettingSmallService.deleteFormSettingSmallByFormSettingSmallIds(formSettingSmallIds));
    }
}
